package io.geekidea.springbootplus.system.controller;

import com.alibaba.fastjson.JSONObject;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.system.service.SmsCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Classname SmsController
 * @Description 短信相关
 * @Date 2019/10/12 14:58
 * @Created by Yrd
 */
@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    private SmsCodeService smsCodeService;

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/getSmsCode")
    public ApiResult<?> getSmsCode(@RequestBody JSONObject jsonObject) {
        try {
            String phone = jsonObject.getString("mobile");
            String method = jsonObject.getString("method");
            smsCodeService.createSmsCode(phone,method);
            return ApiResult.ok("验证码发送成功,请注意查收");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ApiResult.ok("验证码发送失败");
    }

}
